/* tslint:disable */
/* eslint-disable */
{{>licenseInfo}}

{{#includeFetchAdapter}}
import fetchAdapter from "konfig-axios-fetch-adapter"
{{/includeFetchAdapter}}

type ApiKey =
  | string
  | ((keyParamName: string) => string)
  | ((keyParamName: string) => Promise<string>)
  | { [apiKeyName: string]: string | undefined };

export interface ConfigurationParameters {
{{#clientState}}
    {{{.}}}?: string;
{{/clientState}}
{{#clientStateWithExamples}}
    {{{name}}}?: string;
{{/clientStateWithExamples}}
{{#hasMultipleApiKeys}}
{{#apiKeyMethods}}
    {{> securityKeyName}}?: string;
{{/apiKeyMethods}}
{{/hasMultipleApiKeys}}
{{#removeDefaultConfigurationParameters}}
{{^hasMultipleApiKeys}}
{{#apiKeyMethods}}
    {{> configuration_api_key}}
{{/apiKeyMethods}}
{{/hasMultipleApiKeys}}
{{#httpBearerMethods}}
{{#-first}}
    {{> configuration_access_token}}
{{/-first}}
{{/httpBearerMethods}}
{{/removeDefaultConfigurationParameters}}{{^removeDefaultConfigurationParameters}}
    {{> configuration_api_key}}
    username?: string;
    password?: string;
    {{> configuration_access_token}}{{/removeDefaultConfigurationParameters}}
    basePath?: string;
    baseOptions?: any;
{{#includeFetchAdapter}}
    useFetch?: boolean;
{{/includeFetchAdapter}}
{{#hasOAuthMethods}}
    oauthTokenUrl?: string;
    oauthClientId?: string;
    oauthClientSecret?: string;
{{/hasOAuthMethods}}
    userAgent?: string;
    formDataCtor?: new () => any;
}

export class Configuration {
{{#clientState}}
    /**
    * Client state
    */
    {{{.}}}?: string;
{{/clientState}}
{{#clientStateWithExamples}}
    /**
    * Client state
    */
    {{{name}}}?: string;
{{/clientStateWithExamples}}
    {{> configuration_api_key}}
    /**
     * parameter for basic security
     *
     * @type {string}
     * @memberof Configuration
     */
    username?: string;
{{#hasOAuthMethods}}
    /**
     * token url for OAuth2 Application flow
     */
    oauthTokenUrl?: string;
    /**
     * client id for OAuth2 Application flow
     */
    oauthClientId?: string;
    /**
     * client secret for OAuth2 Application flow
     */
    oauthClientSecret?: string;
{{/hasOAuthMethods}}
    /**
     * parameter for basic security
     *
     * @type {string}
     * @memberof Configuration
     */
    password?: string;
    /**
     * parameter for oauth2 security
     * @param name security name
     * @param scopes oauth2 scope
     * @memberof Configuration
     */
    accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
    /**
     * When the access token expires, measured in Unix time in seconds
     */
    accessTokenExpiresIn?: number;
    /**
     * override base path
     *
     * @type {string}
     * @memberof Configuration
     */
    basePath?: string;
    /**
     * base options for axios calls
     *
     * @type {any}
     * @memberof Configuration
     */
    baseOptions?: any;
    /**
     * The FormData constructor that will be used to create multipart form data
     * requests. You can inject this here so that execution environments that
     * do not support the FormData class can still run the generated client.
     *
     * @type {new () => FormData}
     */
    formDataCtor?: new () => any;
    /**
     * Default User-Agent header
     */
    userAgent: string;

    constructor(param: ConfigurationParameters{{> configuration_default}}) {
{{#clientState}}
        this.{{{.}}} = param.{{{.}}}
{{/clientState}}
{{#clientStateWithExamples}}
        this.{{{name}}} = param.{{{name}}}
{{/clientStateWithExamples}}{{#removeDefaultConfigurationParameters}}
{{^hasMultipleApiKeys}}
{{#apiKeyMethods}}
        this.apiKey = param.apiKey
{{/apiKeyMethods}}
{{/hasMultipleApiKeys}}
        {{/removeDefaultConfigurationParameters}}{{^removeDefaultConfigurationParameters}}
        this.apiKey = param.apiKey{{/removeDefaultConfigurationParameters}}
        if (this.apiKey === undefined) {
            this.apiKey = {}
{{#hasMultipleApiKeys}}
{{#apiKeyMethods}}
            if (param.{{> securityKeyName}} !== undefined)
                this.apiKey["{{> securityKeyName}}"] = param.{{> securityKeyName}}
{{/apiKeyMethods}}
{{/hasMultipleApiKeys}}
        }{{#removeDefaultConfigurationParameters}}
        {{#httpBearerMethods}}
        {{#-first}}
        this.accessToken = param.accessToken;
        {{/-first}}
        {{/httpBearerMethods}}
        {{/removeDefaultConfigurationParameters}}{{^removeDefaultConfigurationParameters}}
        this.username = param.username;
        this.password = param.password;
        this.accessToken = param.accessToken;{{/removeDefaultConfigurationParameters}}
        this.basePath = param.basePath;
        this.baseOptions = param.baseOptions ?? {};
{{#includeFetchAdapter}}
        if (param.useFetch ?? true) {
            this.baseOptions["adapter"] = fetchAdapter
        }
{{/includeFetchAdapter}}
        this.userAgent = param.userAgent === undefined ? "{{#userAgent}}{{{userAgent}}}{{/userAgent}}{{^userAgent}}Konfig{{/userAgent}}/{{{npmVersion}}}/typescript" : param.userAgent;
{{#hasOAuthMethods}}
        this.oauthTokenUrl = param.oauthTokenUrl;
        this.oauthClientId = param.oauthClientId;
        this.oauthClientSecret = param.oauthClientSecret;
{{/hasOAuthMethods}}
        this.formDataCtor = param.formDataCtor;
    }

    /**
     * Check if the given MIME is a JSON MIME.
     * JSON MIME examples:
     *   application/json
     *   application/json; charset=UTF8
     *   APPLICATION/JSON
     *   application/vnd.company+json
     * @param mime - MIME (Multipurpose Internet Mail Extensions)
     * @return True if the given MIME is JSON, false otherwise.
     */
    public isJsonMime(mime: string): boolean {
        const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
        return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
    }
}
